#pragma once

#include "PluginBase.h"

class ATL_NO_VTABLE CQipPlugin
	: public CPluginBase
	, public ATL::CComObjectRootEx<ATL::CComSingleThreadModel>
	, public IQIPPlugin
{
public:
	CQipPlugin();

BEGIN_COM_MAP(CQipPlugin)
	// O Brother, Where Art Thou?
	COM_INTERFACE_ENTRY_IID(IID_IUnknown, IQIPPlugin)
END_COM_MAP()

	STDMETHOD_(PluginInfo*, GetPluginInfo)();
	STDMETHOD_(VOID, OnQipMessage)(PluginMessage* plugMsg);

	HRESULT Init(IQIPPluginService* pPluginService)
	{
		m_pPluginService = pPluginService;
		return S_OK;
	}

private:
	PluginSpecific* m_pPluginSpecific;
	PluginInfo pluginInfo;
	AddBtnInfo bInfo;
	int actionId;

	ATL::CComPtr<IQIPPluginService> m_pPluginService;

	ATL::CComBSTR m_bstrUserStatus;
	ATL::CComBSTR m_bstrUserDescription;
	int           m_nUserPicture;

	virtual const std::string GetUserName() const
	{
		if (!m_pPluginSpecific || !m_pPluginSpecific->Wstr1)
			return "";

		return std::string(ATL::CW2AEX<256>(m_pPluginSpecific->Wstr1, CP_UTF8));
	}

	virtual const std::string GetPasswordHash() const
	{
		if (!m_pPluginSpecific || !m_pPluginSpecific->Wstr2)
			return "";

		return std::string(ATL::CW2AEX<256>(m_pPluginSpecific->Wstr2, CP_UTF8));
	}

	virtual void OnSetLocation
		( IN const std::string& strLocation
		);

	void UpgradeOptions();

	void onStart();
	void onStop();
	void onButtonAdd();
	void onButtonClick(PluginMessage* plugMsg);
	INT_PTR onOptions
		( IN HWND hWndOwner
		);

	void sendMessage(int protocolHandle, int accountName);
	void getStatus();
};

typedef ATL::CComObject<CQipPlugin> CoQipPlugin;
